package com.fastloan.jn.mgt.all.table.util;

import com.google.gson.*;

import java.lang.reflect.Type;
import java.math.BigDecimal;

/**
 * Created by gelon on 2017/11/2.
 */
public class BigDecimalAdapter implements JsonSerializer<BigDecimal>,JsonDeserializer<BigDecimal>{
    @Override
    public BigDecimal deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
        if(json.getAsString().equals("") || json.getAsString().equals("null")){
            return BigDecimal.ZERO ;
        }
        return json.getAsBigDecimal();
    }

    @Override
    public JsonElement serialize(BigDecimal src, Type typeOfSrc, JsonSerializationContext context) {
        return new JsonPrimitive(src);
    }
}
